﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ChangePassword.aspx.cs" Inherits="ExaminationSys.ChangePassword"    MasterPageFile="~/View/Share/Index.Master" %>
<%@ Import Namespace="Ext.Net" %>
<%@ Import Namespace="ExaminationSys.Helper" %>
<%@ Import Namespace="Ext.Net.Utilities"%>
<%@ Import Namespace="System.Collections.Generic" %>


<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<asp:Content ID="head" ContentPlaceHolderID="head" runat="server">
<link type="text/css" rel="stylesheet" media="all" href="css/others.css" />
<style type="text/css">
    .current a:hover
    {
        color: #333333;
        text-decoration: none;
        cursor: default;
    }
  
   .box{width:100%;text-align:center;}
.box .fixie{width:320px;margin:0 auto;text-align:left;}
</style>
 <script src="js/jquery.js" type="text/javascript"></script>

   <script type="text/javascript">
       $(function () {
           $("#btnSignOut").click(function () {
               var answer = confirm("是否退出?");
               if (answer) {

                   $.ajax({
                       type: "GET",
                       cache: false,
                       contentType: "application/json",
                       url: "ashx/StudentSignOutHandler.ashx",
                       dataType: 'json',
                       data: null,
                       async: false,
                       success: function (data) {
                           if (data != '200') {
                               alert('操作失败'); return false;
                           }
                           else {
                               var host = window.location.host;
                               window.location.href = "http://" + host + "/Index.aspx";
                           }
                       }
                   });
               }
           });
       });
</script>
<script runat="server">
    public void BtnCancel_Click(object sender, DirectEventArgs e)
    {
        Response.Redirect("Index.aspx");
    }

    public void BtnOk_Click(object sender, DirectEventArgs e)
    {
        var pwd = TB_OldPwd.Text;// e.ExtraParams["pwd"];
        if (string.IsNullOrEmpty(pwd))
        {
            MessageBoxHelper.ShowError("原密码不能为空");
            return;
        }
        var newpwd = TB_NewPwd.Text;// e.ExtraParams["npwd"];// TB_NewPwd.Text;
        if (string.IsNullOrEmpty(newpwd))
        {
            MessageBoxHelper.ShowError("新密码不能为空");
            return;
        }

        var confirmPwd = TB_ConfirmNewPwd.Text;// e.ExtraParams["cpwd"];// TB_ConfirmNewPwd.Text.Trim();
        if (newpwd != confirmPwd)
        {
            MessageBoxHelper.ShowError("确认密码输入不正确");
            return;
        }

        var retCode = FormsAuthenticationHelper.CheckStudentPwd(pwd);

        if (retCode == -1)
        {
            MessageBoxHelper.ShowWarning("身份验证失败，请退出后重新登录.");
            return;
            // Response.Redirect("~/Account/Login.aspx");
        }

        if (retCode == 0)
        {
            MessageBoxHelper.ShowError("原密码输入不正确");
            return;
        }

        retCode = FormsAuthenticationHelper.UpdateStudentPwd(newpwd);
        if (retCode == -1)
        {
            MessageBoxHelper.ShowWarning("身份验证失败，请退出后重新登录.");
            return;
        }
        if (retCode == 0)
        {
            MessageBoxHelper.ShowError("保存失败");
            return;
        }
        MessageBoxHelper.ShowInfo("密码修改成功");
       // Response.Redirect("Index.aspx");

    }
</script>
</asp:Content>
<asp:Content ID="headerContent" ContentPlaceHolderID="HeaderHolder" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server">
       
    </ext:ResourceManager>
    <div class="h-top">
        <div class="logo fl"><img src="images/logo.gif" alt="上海交通大学英语学习中心"/></div>
        <div class="navandsearch fr">
            <ul class="nav">
                  <li><a class="nav-home" href="Index.aspx" title="首页">首页</a></li>
                <li><a class="nav-info" href="Newslist.aspx" title="信息快递">信息快递</a></li>
                <li><a class="nav-help" href="Help.aspx" title="帮助">帮助</a></li>
            </ul>
            <div class="h-search">
                <input id="textKey" class="text" name="" type="text" value="搜索信息" />
                <input id="btnSearch" class="publicbtn btn-search" name="" type="button" value="搜索" />
            </div>
        </div><!--end navandsearch-->
    </div>
    <div class="h-banner"><img src="images/pic/pic02.jpg" width="966" height="308"/></div>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentHolder" runat="server">
<div class="side">
        	<div class="box203">
            	<div class="titles"><img src="images/tit_xx.gif" alt="用户信息"/></div>
            	<div class="conts side-login-on">
                	<p class="tit"><span class="red">欢迎您！</span><span><%=LoginName%></span>同学</p>
                	<ul>
                    	<li><a href="javascript:void(0);">个人资料</a></li>
                        <li><a href="ChangePassword.aspx">密码修改</a></li>
                    </ul>
                    
                    <div class="button">                    
                    <a href="StudyCenter.aspx" id="btnStudycenter"><span style="border:1px solid #e3e3e3;color:red;padding:3px;margin:18px">学习中心</span></a>
                    <input id="btnSignOut" class="publicbtn btn-logout" name="" type="button"  value="退出"/></div>	
                </div>
                <div class="box-bbg"></div>
            </div>
            <div class="side-bang">
                <ul class="red">
                    <li class="li_1"><%=DiligentRank %></li>
                    <li class="li_2"><%=ChampionRank%></li>
                </ul>
            </div>
            
            <div class="login-on-info">
            	<h3><span>登录信息</span></h3>
                <p> 您共登陆了 <b><span class="red"><%= LoginCount%></span> 次</b></p>
                <p class="his"> 您的上次登陆时间为：<span class="red"><%=LastLoginTime%></span></p>
            </div>
           
        </div>
    <!--end side-->


    <div class="contents">
       <div class="other-titles">
            <span class="subtit">修改密码</span>
            <div class="box" >
                    <div class="fixie">
                     <ext:FormPanel 
                   runat="server" ID="FormPanel1" 
            Border="false"
            Icon="Application"
            Height="150" 
            Width="300" 
            ButtonAlign="Center"
             Resizable="false"          
            Modal="true"
                   >
                    <Items>
                      <ext:TextField ID="TB_OldPwd"  InputType="Password" AllowBlank="false"   runat="server" FieldLabel="原密码" />   
                         <ext:TextField ID="TB_NewPwd" InputType="Password"  AllowBlank="false"    runat="server" FieldLabel="新密码" />   
                         <ext:TextField ID="TB_ConfirmNewPwd" runat="server"  AllowBlank="false" InputType="Password"  FieldLabel="确认新密码" />
                    </Items>
                   <Buttons>
                        <ext:Button
                            ID="BtnOK"
                            runat="server" 
                            Text="保存"  
                            Disabled="true"
                            FormBind="true">
                            <DirectEvents>
                                    <Click OnEvent="BtnOk_Click">
                                        <EventMask ShowMask="true" Msg="正在处理..." MinDelay="500" />
                                        <%--<ExtraParams>
                                             <ext:Parameter Name="pwd"  Value="#{TB_OldPwd}.getValue()" Mode="Raw"/>
                                             <ext:Parameter Name="npwd"  Value="#{TB_NewPwd}.getValue()" Mode="Raw"/>
                                             <ext:Parameter Name="cpwd"  Value="#{TB_ConfirmNewPwd}.getValue()" Mode="Raw"/>
                                        </ExtraParams>--%>
                                    </Click>
                        
                                </DirectEvents>
                            <Listeners>
                             
                                <Click  Handler="if (!#{TB_OldPwd}.validate() || !#{TB_OldPwd}.validate()||!#{TB_ConfirmNewPwd}.validate()) {
                                Ext.Msg.show({title:'提示信息',msg:'原密码<br/>新密码<br/>确认密码 <br/>必须填写',buttons:Ext.Msg.OK,icon:Ext.MessageBox.WARNING}); return false;}" />
                            </Listeners>
                        </ext:Button>
                        <ext:Button ID="BtnCancel" runat="server" Text="返回" >
                           <%--  <DirectEvents><Click  OnEvent="BtnCancel_Click" ></Click> 
                            </DirectEvents>--%>
                            <Listeners>
                                <Click Handler="javascript:window.history.go(-1);"></Click>
                            </Listeners>
                        </ext:Button>
                    </Buttons>
                    <Listeners>
                        <ValidityChange Handler="#{BtnOK}.setDisabled(!valid);" />
                    </Listeners>
                </ext:FormPanel> 
                 </div>
            </div>
        </div>
    </div>
    <!--end contents-->
</asp:Content>
